package commandes;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import bdd.DBS;
import beans.Logement;

// Cette cde recupere l'ensemble des clients:
//
public class CommandeLogCrit implements Commande {
  private String next;

  public CommandeLogCrit(String next) {
        this.next = next;
  }

  public String execute(HttpServletRequest req) throws Exception {
	  DBS db = DBS.getInstance();
	 
	  
	  if(req.getParameter("quartier")!=null && req.getParameter("ville") != null){
		  String ville = req.getParameter("ville");
		  String quartier = req.getParameter("quartier");
		  List<Logement> logs = db.getDB_Logement().getLogements("select * from Logement where quartier='"+quartier+"' and adresse='"+ville+"'"
				  																		 +"EXCEPT (select Logement.idlogt,idproprio,quartier,adresse,type,loyer from Logement,Location where Logement.idlogt = Location.idlogt)");
		  req.setAttribute("logements", logs);
	  }
	  else{
		  List<Logement> logs = new ArrayList<Logement>();
		  req.setAttribute("logements", logs);
	  }
      return next;
  }

}
